﻿/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_PS_UTIL_H
#define MK_PS_UTIL_H
#include "MkMedia/MkMediaUtil.h"

#define PsStartCode         0x000001BA
#define PsSystemStartCode   0x000001BB
#define PsMapStartCode      0x000001BC
#define PsEndCode           0x000001B9
#define PsPrivateCode       0x000001BD
#define PsHeaderLen         14  //more than 14 byte
#define PsSystemHeaderLen   12
#define PsMapHeaderLen      10



typedef enum _trick_mode_control
{
    FastForward = 0x00,
    SlowMotion = 0x01,
    FreezeFrame = 0x02,
    FastReverse = 0x03,
    SlowReverse = 0x04
}MkTrickModeControl;

// ISO/IEC 13818-1:2015 (E)
// 2.4.4.9 Semantic definition of fields in transport stream program map section
// Table 2-34 - Stream type assignments(p69)
typedef enum _ps_stream_type
{
    PsStreamReserved = 0x00,  // ISO/IEC 11172-2 Video
    PsStreamMepg1 = 0x01,  // Rec. ITU-T H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream(see Note 2)
    PsStreamMepg2 = 0x02,  // ISO/IEC 11172-3 Audio
    PsStreamAudioMepeg1 = 0x03,  // ISO/IEC 13818-3 Audio
    PsStreamMp3 = 0x04,  // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 private_sections
    PsStreamPrivateSection = 0x05,  // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 PES packets containing private data
    PsStreamPrivateData = 0x06,  // ISO/IEC 13522 MHEG
    PsStreamMheg = 0x07,  // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC
    PsStreamDsmcc = 0x08,  // Rec. ITU-T H.222.1
    PsStreamH222Atm = 0x09,  // ISO/IEC 13818-6(Extensions for DSM-CC) type A
    PsStreamDsmccA = 0x0a,  // ISO/IEC 13818-6(Extensions for DSM-CC) type B
    PsStreamDsmccB = 0x0b,  // ISO/IEC 13818-6(Extensions for DSM-CC) type C
    PsStreamDsmccC = 0x0c,  // ISO/IEC 13818-6(Extensions for DSM-CC) type D
    PsStreamDsmccD = 0x0d,  // Rec. ITU-T H.222.0 | ISO/IEC 13818-1 auxiliary
    PsStreamAac = 0x0f,  // ISO/IEC 13818-7 Audio with ADTS transport syntax
    PsStreamMpeg4 = 0x10,  // ISO/IEC 14496-2 Visual
    PsStreamMpeg4AacLatm = 0x11,  // ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3
    PsStreamMpeg4Pes = 0x12,  // ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets
    PsStreamMpegSections = 0x13,  // ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC 14496_sections
    PsStreamMpeg4Sdp = 0x14,  // ISO/IEC 13818-6 Synchronized Download Protocol
    PsStreamMpegPesMeta = 0x15,  // Metadata carried in PES packets
    PsStreamSectionMeta = 0x16,  // Metadata carried in metadata_sections
    PsStreamDsmccData = 0x17,  // Metadata carried in ISO/IEC 13818-6 Data Carousel
    PsStreamDsmccObject = 0x18,  // Metadata carried in ISO/IEC 13818-6 Object Carousel
    PsStreamDsmccSdp = 0x19,  // Metadata carried in ISO/IEC 13818-6 Synchronized Download Protocol
    PsStreamMpeg2Ipmp = 0x1a, // IPMP stream (defined in ISO/IEC 13818-11, MPEG-2 IPMP)
    PsStreamH264 = 0x1b, // H.264
    PsStreamMpeg4Aac = 0x1c, // ISO/IEC 14496-3 Audio, without using any additional transport syntax, such as DST, ALS and SLS
    PsStreamMpeg4Text = 0x1d, // ISO/IEC 14496-17 Text
    PsStreamAuxVideo = 0x1e, // Auxiliary video stream as defined in ISO/IEC 23002-3
    PsStreamH264Svc = 0x1f, // SVC video sub-bitstream of an AVC video stream conforming to one or more profiles defined in Annex G of Rec. ITU-T H.264 | ISO/IEC 14496-10
    PsStreamH264Mvc = 0x20, // MVC video sub-bitstream of an AVC video stream conforming to one or more profiles defined in Annex H of Rec. ITU-T H.264 | ISO/IEC 14496-10
    PsStreamJmpeg2000 = 0x21, // Video stream conforming to one or more profiles as defined in Rec. ITU-T T.800 | ISO/IEC 15444-1
    PsStreamMpeg23D = 0x22, // Additional view Rec. ITU-T H.262 | ISO/IEC 13818-2 video stream for service-compatible stereoscopic 3D services
    PsStreamMpeg43D = 0x23, // Additional view Rec. ITU-T H.264 | ISO/IEC 14496-10 video stream conforming to one or more profiles defined in Annex A for service-compatible stereoscopic 3D services
    PsStreamH265 = 0x24, // Rec. ITU-T H.265 | ISO/IEC 23008-2 video stream or an HEVC temporal video sub-bitstream
    PsStreamH265Subset = 0x25, // HEVC temporal video subset of an HEVC video stream conforming to one or more profiles defined in Annex A of Rec. ITU-T H.265 | ISO/IEC 23008-2
    PsStreamH264Mvcd = 0x26, // MVCD video sub-bitstream of an AVC video stream conforming to one or more profiles defined in Annex I of Rec. ITU-T H.264 | ISO/IEC 14496-10
    PsStreamVp8 = 0x9d,
    PsStreamVp9 = 0x9e,
    PsStreamAv1 = 0x9f, // 0x27-0x7E Rec. ITU-T H.222.0 | ISO/IEC 13818-1 Reserved
    PsStreamIpmp = 0x7F, // IPMP stream

    // 0x80-0xFF User Private
    PsStreamVideoCavs = 0x42, // ffmpeg/libavformat/mpegts.h
    PsStreamAudioAc3 = 0x81, // ffmpeg/libavformat/mpegts.h
    PsStreamAudioEac3 = 0x87, // ffmpeg/libavformat/mpegts.h
    PsStreamAudioDts = 0x8a, // ffmpeg/libavformat/mpegts.h
    PsStreamVideoDirac = 0xd1, // ffmpeg/libavformat/mpegts.h
    PsStreamVideoAc1 = 0xea, // ffmpeg/libavformat/mpegts.h
    PsStreamVidoeSvac = 0x80, // GBT 25724-2010 SVAC(2014)
    PsStreamAudioSvac = 0x9B, // GBT 25724-2010 SVAC(2014)
    PsStreamALaw = 0x90,	// GBT 25724-2010 SVAC(2014)
    PsStreamULaw = 0x91,
    PsStreamG722 = 0x92,
    PsStreamG723 = 0x93,
    PsStreamG729 = 0x99,
    PsStreamOpus = 0x9c,
} MkPsStreamType;

class MkApi CMkPsUtil
{
public:
    CMkPsUtil() {}
    ~CMkPsUtil() {}
    static MkCodecType PsCodecToMkCodecType(const MkPsStreamType& PsCodec);
    static MkPsStreamType MkCodecTypeToPsCodec(const MkCodecType& Codec);
};


#endif
